package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.base.domain.ShopCar;
import cn.wolfcode.trip.base.service.IShopCarService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.sun.deploy.net.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/shopcars")
public class ShopCarController {
    @Autowired
    private IShopCarService shopCarService;




    //查询用户购物车中所有的商品
    @GetMapping
    public Object listByUserId(Long userId) {
        List<ShopCar> shopCars = shopCarService.selectByUserId(userId);
        return shopCarService.selectByUserId(userId);
    }








    //购物车增加商品
    @PostMapping("/goods")
    public Object SaveInShopCar(ShopCar shopCar) {
        shopCarService.insert(shopCar);
        return new JSONResult();
    }









    //结算
    @GetMapping("/sum")
    public Object sum(Long userId,int sum){
        Boolean b = shopCarService.Calculation(userId,sum);
        Map<String ,Boolean> map = new HashMap<>();
        map.put("result",b);
        return map;
    }
}
